# serializers.py
from rest_framework import serializers
from .models import User, UserProfile


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['phone']  # 只返回 phone 字段


class UserProfileSerializer(serializers.ModelSerializer):
    # 直接将关联用户的 phone 作为字段返回
    user_phone = serializers.CharField(source='user.phone', read_only=True)

    class Meta:
        model = UserProfile
        fields = [
            'id', 'user_phone', 'gender', 'birthdate',
            'height', 'weight', 'avatar_url',
            'is_realname', 'realname', 'id_number'
        ]